/* Copyright (c) 2024 Huawei Technologies Co., Ltd.
 * This file is a part of the CANN Open Software.
 * Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 * ===================================================================================================================*/

#include "debug/ge_util.h"
#include "graph/ge_attr_value.h"

namespace ge {
graphStatus AttrValueImpl::GetValue(const AttrValue &obj, AttrValue::STR &val) {
  if (obj.impl != nullptr) {
    return obj.impl->geAttrValue_.GetValue<AttrValue::STR>(val);
  }
  return GRAPH_FAILED;
}

graphStatus AttrValueImpl::GetValue(const AttrValue &obj, AttrValue::INT &val) {
  if (obj.impl != nullptr) {
    return obj.impl->geAttrValue_.GetValue<AttrValue::INT>(val);
  }
  return GRAPH_FAILED;
}

graphStatus AttrValueImpl::GetValue(const AttrValue &obj, AttrValue::FLOAT &val) {
  if (obj.impl != nullptr) {
    return obj.impl->geAttrValue_.GetValue<AttrValue::FLOAT>(val);
  }
  return GRAPH_FAILED;
}

graphStatus AttrValueImpl::GetValue(const AttrValue &obj, AscendString &val) {
  std::string val_get;
  const auto status = obj.GetValue(val_get);
  if (status != GRAPH_SUCCESS) {
    return status;
  }
  val = AscendString(val_get.c_str());
  return GRAPH_SUCCESS;
}

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AttrValue::AttrValue() {
  impl = ComGraphMakeShared<AttrValueImpl>();
}

graphStatus AttrValue::GetValue(AttrValue::STR &val) const {
  return AttrValueImpl::GetValue(*this, val);
}

graphStatus AttrValue::GetValue(AttrValue::INT &val) const {
  return AttrValueImpl::GetValue(*this, val);
}

graphStatus AttrValue::GetValue(AttrValue::FLOAT &val) const {
  return AttrValueImpl::GetValue(*this, val);
}

graphStatus AttrValue::GetValue(AscendString &val) {
  return AttrValueImpl::GetValue(*this, val);
}
}  // namespace ge
